package com.kefu.call.vo;

import java.util.List;

import javax.validation.constraints.Size;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.common.context.KefuContext;
import com.kefu.common.mybatis.Order;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

/**
 * @author francis
 * @date 2021/05/22
 */
@Data
@ToString(callSuper = true)
@ApiModel(description = "回收活动清单")
public class ActivityInventoryInfoRecoveryVo{

		@ApiModelProperty(name = "recoveryType", value = "回收类型", example="1",notes= "1 简单回收 按照清单分配，2高级回收 根据查询条件回收")
		int recoveryType;
		
		@ApiModelProperty(name = "simpleRecovery", value = "按照清单回收")
		SimpleRecoveryVo simpleRecovery;
		
		@ApiModelProperty(name = "advancedRecovery", value = "按照查询条件回收")
		AdvancedRecoveryVo advancedRecovery;
		
		@Data
		@ToString(callSuper = true)
		@ApiModel(description = "简单回收")
		public static class SimpleRecoveryVo{
			
			@Size(min=1)
			@ApiModelProperty(name = "inventoryIds", value = "待回收清单")
			List<String> inventoryIds;
			
		}
		

		
		@Data
		@ToString(callSuper = true)
		@ApiModel(description = "高级回收")
		public static class AdvancedRecoveryVo{
			
			@ApiModelProperty(name = "pageNo", value = "起始页码", example = "1",hidden=true)
			int pageNo = 1;
			@ApiModelProperty(name = "pageSize", value = "分配条数", example = "100")
			int pageSize = 1000;
			@ApiModelProperty(name = "orderField", value = "排序字段", example = "id")
			String orderField;
			@ApiModelProperty(name = "order", value = "排序状态", example = "ASC")
			Order order = Order.ASC;
			@ApiModelProperty(value = "活动ID")
			private String activityId;
			@ApiModelProperty(value = "创建时间")
			private Long createTimeStart;
		    @ApiModelProperty(value = "创建时间结束")
		    private Long createTimeEnd;
		    @ApiModelProperty(value = "修改时间开始")
		    private Long updateTimeStart;
		    @ApiModelProperty(value = "修改时间结束")
		    private Long updateTimeEnd;
			@ApiModelProperty(value = "数据状态0 无效，1有效",hidden=true)
			private Integer dataStatus=1;
			@ApiModelProperty(value = "清单状态",example="2",allowableValues="2,3",notes="1 未分配，2已分配，3处理中，4预约，5处理完成，6 处理失败")
			private Integer inventoryStatus=2;
			@ApiModelProperty(value = "客户ID")
			private String customerId;
			@ApiModelProperty(value = "客户名称")
			private String customerName;
			
			@ApiModelProperty(hidden = true)
		    public <T>QueryWrapper<T> getExample() {

				QueryWrapper<T> builder = builder();
		        if (StringUtils.isNotBlank(orderField) && !orderField.equals("id")) {
		            order.order(builder, orderField);
		        }
		        
		        return builder;
		    }
			
			@ApiModelProperty(hidden = true)
			   public <T>QueryWrapper<T> builder() {
		 		QueryWrapper<T> wrapper=Wrappers.query();
		        if (createTimeStart != null) {
				    wrapper.ge("create_time", createTimeStart);
				}
				if (createTimeEnd != null) {
				    wrapper.le("create_time", createTimeEnd);
				}
				if (updateTimeStart != null) {
				    wrapper.ge("update_time", updateTimeStart);
				}
				if (updateTimeEnd != null) {
				    wrapper.le("update_time", updateTimeEnd);
				}
				if (activityId != null) {
					wrapper.eq("activity_id", activityId);
				}
				if (customerId != null) {
					wrapper.eq("customer_id", customerId);
				}
				if (customerName != null) {
					wrapper.eq("customer_name", customerName);
				}
			   
			    wrapper.eq("data_status", 1);
			    wrapper.eq("inventory_status", inventoryStatus);
			    wrapper.eq("tenant_id", KefuContext.getKefuContext().getTenantId());
			    
			    return wrapper;
			}

		}
		

}